/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OplysningerPanel.java
 *
 * Created on May 9, 2012, 2:17:47 PM
 */
package view.elev;

import control.ElevControl;
import java.util.Iterator;
import model.Elev;
import model.ElevTelefon;
 
/**
 *
 * @author Marc
 */
public class OplysningerPanel extends javax.swing.JPanel {
private ElevControl elevControl;
private Elev[] el;
    /** Creates new form OplysningerPanel */
private void updateElev(Elev elev){
    
    
    CPR.setText(elev.getCpr());
    Fornavn.setText(elev.getFornavn());
    Efternavn.setText(elev.getEfternavn());
    Hold.setText(elev.getHold().getHoldId());
    Adresse.setText(elev.getAdresse());
    Postnr.setText(elev.getPostnr().getPostNummer());
    by.setText(elev.getPostnr().getByen());
    RekvirerendeKomm.setText(elev.getRekrKommune());
    RekvirerendeSkole.setText(elev.getRekrSkole());
    telefon.setText("");
    Indskrevet.setText(elev.getIndskrivelse().toString()));
    Udskrevet.setText(elev.getUdskrivning().toString());
      Iterator telefonIter = elev.getElevTelefons().iterator();
                while (telefonIter.hasNext()) {
                    ElevTelefon c = (ElevTelefon) telefonIter.next();
                    telefon.append(c.getId().getTelefon() + "\n");
                }
    // telefon.setText(elev.getElevTelefons().iterator());
}
private void clearFelter() {
    Indskrevet.setText("");
    Udskrevet.setText("");
    RekvirerendeSkole.setText("");
    RekvirerendeKomm.setText("");
    telefon.setText("");
        CPR.setText("");
    Fornavn.setText("");
    Efternavn.setText("");
    Hold.setText("");
    Adresse.setText("");
    Postnr.setText("");
    by.setText("");
    }
    public OplysningerPanel() {
        
        initComponents();
        
         elevControl = new ElevControl();
         el = elevControl.getElever();
         
         for (int i = 0; i < el.length; i++) {
            VaelgElev.addItem(el[i].getFornavn() + " "+ el[i].getEfternavn());           
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        VaelgElev = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        CPR = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        Fornavn = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        Efternavn = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        Adresse = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        Postnr = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        by = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jLabel13 = new javax.swing.JLabel();
        Hold = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jList3 = new javax.swing.JList();
        jLabel20 = new javax.swing.JLabel();
        RekvirerendeKomm = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        RekvirerendeSkole = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        note = new javax.swing.JTextArea();
        jLabel16 = new javax.swing.JLabel();
        Indskrevet = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        Udskrevet = new javax.swing.JTextField();
        jScrollPane5 = new javax.swing.JScrollPane();
        telefon = new javax.swing.JTextArea();

        setMaximumSize(new java.awt.Dimension(1016, 600));
        setMinimumSize(new java.awt.Dimension(1016, 600));
        setPreferredSize(new java.awt.Dimension(1024, 600));
        setLayout(null);

        jLabel1.setText("Elev:");
        add(jLabel1);
        jLabel1.setBounds(20, 10, 60, 14);

        VaelgElev.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Vælg Elev" }));
        VaelgElev.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VaelgElevActionPerformed(evt);
            }
        });
        add(VaelgElev);
        VaelgElev.setBounds(20, 30, 190, 20);

        jLabel2.setText("CPR:");
        add(jLabel2);
        jLabel2.setBounds(20, 70, 80, 14);

        CPR.setEditable(false);
        CPR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CPRActionPerformed(evt);
            }
        });
        add(CPR);
        CPR.setBounds(20, 90, 150, 20);

        jLabel3.setText("Fornavn:");
        add(jLabel3);
        jLabel3.setBounds(20, 120, 100, 14);

        Fornavn.setEditable(false);
        add(Fornavn);
        Fornavn.setBounds(20, 140, 150, 20);

        jLabel4.setText("Efternavn:");
        add(jLabel4);
        jLabel4.setBounds(20, 170, 100, 14);

        Efternavn.setEditable(false);
        Efternavn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EfternavnActionPerformed(evt);
            }
        });
        add(Efternavn);
        Efternavn.setBounds(20, 190, 150, 20);

        jLabel5.setText("Adresse:");
        add(jLabel5);
        jLabel5.setBounds(20, 270, 100, 14);

        Adresse.setEditable(false);
        add(Adresse);
        Adresse.setBounds(20, 290, 150, 20);

        jLabel6.setText("Post Nummer:");
        add(jLabel6);
        jLabel6.setBounds(20, 320, 130, 14);

        Postnr.setEditable(false);
        add(Postnr);
        Postnr.setBounds(20, 340, 50, 20);

        jLabel7.setText("Telefon:");
        add(jLabel7);
        jLabel7.setBounds(20, 420, 90, 10);

        jLabel8.setText("By:");
        add(jLabel8);
        jLabel8.setBounds(20, 370, 70, 10);

        by.setEditable(false);
        add(by);
        by.setBounds(20, 390, 130, 20);

        jLabel9.setText("Billede:");
        add(jLabel9);
        jLabel9.setBounds(740, 30, 80, 14);

        jLabel10.setText("Allergier:");
        add(jLabel10);
        jLabel10.setBounds(620, 350, 90, 14);

        jLabel11.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        add(jLabel11);
        jLabel11.setBounds(740, 50, 250, 250);

        jLabel12.setText("Medicin:");
        add(jLabel12);
        jLabel12.setBounds(830, 350, 100, 14);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        jScrollPane1.setViewportView(jList1);

        add(jScrollPane1);
        jScrollPane1.setBounds(620, 370, 160, 140);

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        jScrollPane2.setViewportView(jList2);

        add(jScrollPane2);
        jScrollPane2.setBounds(830, 370, 160, 140);

        jLabel13.setText("Hold:");
        add(jLabel13);
        jLabel13.setBounds(20, 220, 90, 14);

        Hold.setEditable(false);
        Hold.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HoldActionPerformed(evt);
            }
        });
        add(Hold);
        Hold.setBounds(20, 240, 90, 20);

        jLabel14.setText("Elevens Fag:");
        add(jLabel14);
        jLabel14.setBounds(490, 60, 110, 14);

        jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        jScrollPane3.setViewportView(jList3);

        add(jScrollPane3);
        jScrollPane3.setBounds(490, 80, 160, 220);

        jLabel20.setText("Rekvirerende Kommune:");
        add(jLabel20);
        jLabel20.setBounds(260, 70, 170, 14);

        RekvirerendeKomm.setEditable(false);
        add(RekvirerendeKomm);
        RekvirerendeKomm.setBounds(260, 90, 130, 20);

        jLabel21.setText("Rekvirerende Skole:");
        add(jLabel21);
        jLabel21.setBounds(260, 120, 120, 14);

        RekvirerendeSkole.setEditable(false);
        add(RekvirerendeSkole);
        RekvirerendeSkole.setBounds(260, 140, 170, 20);

        jLabel15.setText("Kommentarer om eleven:");
        add(jLabel15);
        jLabel15.setBounds(260, 350, 320, 14);

        note.setColumns(20);
        note.setEditable(false);
        note.setRows(5);
        jScrollPane4.setViewportView(note);

        add(jScrollPane4);
        jScrollPane4.setBounds(260, 370, 320, 140);

        jLabel16.setText("Indskrevet:");
        add(jLabel16);
        jLabel16.setBounds(260, 200, 80, 14);

        Indskrevet.setEditable(false);
        add(Indskrevet);
        Indskrevet.setBounds(260, 220, 110, 20);

        jLabel17.setText("Udskrevet:");
        add(jLabel17);
        jLabel17.setBounds(260, 250, 80, 14);

        Udskrevet.setEditable(false);
        add(Udskrevet);
        Udskrevet.setBounds(260, 270, 110, 20);

        jScrollPane5.setBackground(Fornavn.getBackground());
        jScrollPane5.setAutoscrolls(true);
        jScrollPane5.setEnabled(false);

        telefon.setBackground(Efternavn.getBackground());
        telefon.setColumns(20);
        telefon.setEditable(false);
        telefon.setForeground(Adresse.getForeground());
        telefon.setLineWrap(true);
        telefon.setRows(5);
        telefon.setBorder(Fornavn.getBorder());
        telefon.setCaretColor(Adresse.getCaretColor());
        telefon.setEnabled(false);
        jScrollPane5.setViewportView(telefon);

        add(jScrollPane5);
        jScrollPane5.setBounds(20, 440, 130, 100);
        jScrollPane5.getAccessibleContext().setAccessibleName("");
    }// </editor-fold>//GEN-END:initComponents

    private void CPRActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CPRActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CPRActionPerformed

    private void VaelgElevActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VaelgElevActionPerformed
      
        if(VaelgElev.getSelectedIndex() != 0){
        updateElev(el[VaelgElev.getSelectedIndex()-1]);
        }else{
            clearFelter();
        }
    }//GEN-LAST:event_VaelgElevActionPerformed

    private void HoldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HoldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_HoldActionPerformed

    private void EfternavnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EfternavnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_EfternavnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Adresse;
    private javax.swing.JTextField CPR;
    private javax.swing.JTextField Efternavn;
    private javax.swing.JTextField Fornavn;
    private javax.swing.JTextField Hold;
    private javax.swing.JTextField Indskrevet;
    private javax.swing.JTextField Postnr;
    private javax.swing.JTextField RekvirerendeKomm;
    private javax.swing.JTextField RekvirerendeSkole;
    private javax.swing.JTextField Udskrevet;
    private javax.swing.JComboBox VaelgElev;
    private javax.swing.JTextField by;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JList jList2;
    private javax.swing.JList jList3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTextArea note;
    private javax.swing.JTextArea telefon;
    // End of variables declaration//GEN-END:variables

    
}
